package com.yanfan.energybilling.controller;

import com.yanfan.common.annotation.Log;
import com.yanfan.common.core.controller.BaseController;
import com.yanfan.common.core.domain.AjaxResult;
import com.yanfan.common.core.page.TableDataInfo;
import com.yanfan.common.enums.BusinessType;
import com.yanfan.common.utils.poi.ExcelUtil;
import com.yanfan.energybilling.domain.PriceScheme;
import com.yanfan.energybilling.service.IPriceSchemeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 价格方案Controller
 *
 * @author kerwincui
 * @date 2025-07-28
 */
@RestController
@RequestMapping("/energy/scheme")
@Api(tags = "价格方案")
public class PriceSchemeController extends BaseController {
    @Autowired
    private IPriceSchemeService priceSchemeService;

    /**
     * 查询价格方案列表
     */
    @PreAuthorize("@ss.hasPermi('energy:scheme:list')")
    @GetMapping("/list")
    @ApiOperation("查询价格方案列表")
    public TableDataInfo list(PriceScheme priceScheme) {
        startPage();
        List<PriceScheme> list = priceSchemeService.selectPriceSchemeList(priceScheme);
        return getDataTable(list);
    }
    /**
     * 查询价格方案列表全部
     */
//    @PreAuthorize("@ss.hasPermi('energy:scheme:list')")
    @GetMapping("/listAll")
    @ApiOperation("查询价格方案列表")
    public AjaxResult listAll() {
        List<PriceScheme> list = priceSchemeService.selectPriceSchemeList(null);
        return success(list);
    }

    /**
     * 导出价格方案列表
     */
    @ApiOperation("导出价格方案列表")
    @PreAuthorize("@ss.hasPermi('energy:scheme:export')")
    @Log(title = "价格方案", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PriceScheme priceScheme) {
        List<PriceScheme> list = priceSchemeService.selectPriceSchemeList(priceScheme);
        ExcelUtil<PriceScheme> util = new ExcelUtil<PriceScheme>(PriceScheme.class);
        util.exportExcel(response, list, "价格方案数据");
    }

    /**
     * 获取价格方案详细信息
     */
    @PreAuthorize("@ss.hasPermi('energy:scheme:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取价格方案详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(priceSchemeService.selectPriceSchemeById(id));
    }

    /**
     * 新增价格方案
     */
    @PreAuthorize("@ss.hasPermi('energy:scheme:add')")
    @Log(title = "价格方案", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增价格方案")
    public AjaxResult add(@RequestBody PriceScheme priceScheme) {
        return toAjax(priceSchemeService.insertPriceScheme(priceScheme));
    }

    /**
     * 修改价格方案
     */
    @PreAuthorize("@ss.hasPermi('energy:scheme:edit')")
    @Log(title = "价格方案", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改价格方案")
    public AjaxResult edit(@RequestBody PriceScheme priceScheme) {
        return toAjax(priceSchemeService.updatePriceScheme(priceScheme));
    }

    /**
     * 删除价格方案
     */
    @PreAuthorize("@ss.hasPermi('energy:scheme:remove')")
    @Log(title = "价格方案", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation("删除价格方案")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(priceSchemeService.deletePriceSchemeByIds(ids));
    }
}
